package yanglei.day0110;

import yanglei.day0109.travel.dao.TourRouteDao;
import yanglei.day0109.travel.dao.impl.TourRouteDaoImpl;
import yanglei.day0109.travel.po.TourRoute;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet(name = "TravleServlet", value = "/TravleServlet")
public class TravleServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 设置中文字符乱乱码，解决request/response响应
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        TourRouteDao tourRouteDao = new TourRouteDaoImpl();
        Map<String,Object> map = new HashMap<>();
        String searchName = request.getAttribute("searchName") == null ? "" :
                String.valueOf(request.getAttribute("searchName"));
        if (!"".equals(searchName)) {
            map.put("trName", searchName);
        }
        List<TourRoute> tourRoutes = tourRouteDao.queryTourRouteByType(map);
        request.setAttribute("tourRoutes",tourRoutes);
        request.getRequestDispatcher("jsp/yanglei/day0110/travelagency.jsp").forward(request,response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
